/****** Object:  StoredProcedure [dbo].[procPR_ActivityType_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_ActivityType_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE PR_ActivityType SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_ActivityType_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_ActivityType_Insert]
(
	@Id uniqueidentifier,
	@Name nvarchar(255),
	@Description ntext,
	@IsActive bit,
	@InsertTimeStamp datetime,
	@UpdateTimeStamp datetime
)
AS
BEGIN
	INSERT INTO dbo.[PR_ActivityType]
	(
		Id,
		Name,
		Description,
		IsActive,
		InsertTimeStamp,
		UpdateTimeStamp
	)
	VALUES
	(
		@Id,
		@Name,
		@Description,
		@IsActive,
		@InsertTimeStamp,
		@UpdateTimeStamp
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_ActivityType_Search]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_ActivityType_Search]
(
	@Name nvarchar(255),
	@IsActive bit,
	@PageIndex int,
	@PageSize int
)AS
BEGIN

  SELECT * FROM
  (
	SELECT DISTINCT PR_ActivityType.*, ROW_NUMBER() OVER(ORDER BY PR_ActivityType.InsertTimeStamp) AS RowNumBer FROM PR_ActivityType
	WHERE PR_ActivityType.Name LIKE '%'+@Name+'%' AND PR_ActivityType.IsActive= @IsActive

   ) AS DataSet
  WHERE RowNumBer > @PageSize * @PageIndex AND RowNumBer <= @PageSize * (@PageIndex + 1)
  ORDER BY RowNumBer
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_ActivityType_SearchCount]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_ActivityType_SearchCount]
(
	@Name nvarchar(255),
	@IsActive bit
)
AS
BEGIN
	SELECT COUNT(0) FROM PR_ActivityType WHERE PR_ActivityType.Name LIKE '%'+@Name+'%' AND PR_ActivityType.IsActive= @IsActive
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_ActivityType_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_ActivityType_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[PR_ActivityType] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_ActivityType_SelectAll]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_ActivityType_SelectAll]

AS
BEGIN
	SELECT * FROM dbo.[PR_ActivityType]
	ORDER BY InsertTimeStamp, Name
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_ActivityType_SelectByName]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_ActivityType_SelectByName]
(
	@Name nvarchar(255)
)
AS
BEGIN
	SELECT * FROM dbo.[PR_ActivityType] WHERE Name LIKE '%' + @Name + '%'
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_ActivityType_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_ActivityType_Update]
(
	@Id uniqueidentifier,
	@Name nvarchar(255),
	@Description ntext,
	@IsActive bit,
	@InsertTimeStamp datetime,
	@UpdateTimeStamp datetime
)
AS
BEGIN
	UPDATE PR_ActivityType SET
		Name = @Name,
		Description = @Description,
		IsActive = @IsActive,
		InsertTimeStamp = @InsertTimeStamp,
		UpdateTimeStamp = @UpdateTimeStamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Page_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Page_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE PR_Page SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Page_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Page_Insert]
(
	@Id uniqueidentifier,
	@PageName nvarchar(100),
	@Url nvarchar(500),
	@Category nvarchar(100),
	@NavigationOrder int,
	@NavigationType nvarchar(50),
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[PR_Page]
	(
		Id,
		PageName,
		Url,
		Category,
		NavigationOrder,
		NavigationType,
		IsActive
	)
	VALUES
	(
		@Id,
		@PageName,
		@Url,
		@Category,
		@NavigationOrder,
		@NavigationType,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Page_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Page_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[PR_Page] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Page_SelectAll]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Page_SelectAll]

AS
BEGIN
	SELECT * FROM dbo.[PR_Page]
	ORDER BY dbo.[PR_Page].Category, NavigationType, NavigationOrder
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Page_SelectByUrl]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Page_SelectByUrl]
(
	@Url nvarchar(500)
)
AS
BEGIN
	SELECT * FROM dbo.[PR_Page] WHERE Url LIKE '%' + @Url + '%'
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Page_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Page_Update]
(
	@Id uniqueidentifier,
	@PageName nvarchar(100),
	@Url nvarchar(500),
	@Category nvarchar(100),
	@NavigationOrder int,
	@NavigationType nvarchar(50),
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE PR_Page SET
		PageName = @PageName,
		Url = @Url,
		Category = @Category,
		NavigationOrder = @NavigationOrder,
		NavigationType = @NavigationType,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Permission_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Permission_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE PR_Permission SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Permission_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Permission_Insert]
(
	@Id uniqueidentifier,
	@PermissionName nvarchar(100),
	@IsSystemData bit,
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[PR_Permission]
	(
		Id,
		PermissionName,
		IsSystemData,
		IsActive
	)
	VALUES
	(
		@Id,
		@PermissionName,
		@IsSystemData,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Permission_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Permission_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[PR_Permission] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Permission_SelectAll]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Permission_SelectAll]

AS
BEGIN
	SELECT * FROM dbo.[PR_Permission]
	ORDER BY dbo.[PR_Permission].PermissionName
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Permission_SelectByName]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Permission_SelectByName]
(
	@PermissionName nvarchar(100)
)
AS
BEGIN
	SELECT * FROM dbo.[PR_Permission] WHERE PermissionName = @PermissionName
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Permission_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Permission_Update]
(
	@Id uniqueidentifier,
	@PermissionName nvarchar(100),
	@IsSystemData bit,
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE PR_Permission SET
		PermissionName = @PermissionName,
		IsSystemData = @IsSystemData,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Role_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Role_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE PR_Role SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Role_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Role_Insert]
(
	@Id uniqueidentifier,
	@SystemId uniqueidentifier,
	@RoleName nvarchar(100),
	@Description nvarchar(500),
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[PR_Role]
	(
		Id,
		SystemId,
		RoleName,
		Description,
		IsActive
	)
	VALUES
	(
		@Id,
		@SystemId,
		@RoleName,
		@Description,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Role_Search]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Role_Search]
(
	@RoleName nvarchar(100),
	@IsActive bit,
	@PageIndex int,
	@PageSize int
)AS
BEGIN

  SELECT * FROM
  (
	SELECT DISTINCT PR_Role.*, ROW_NUMBER() OVER(ORDER BY PR_Role.SystemId) AS RowNumBer FROM PR_Role
	WHERE PR_Role.RoleName LIKE '%'+@RoleName+'%' AND PR_Role.IsActive= @IsActive

   ) AS DataSet
  WHERE RowNumBer > @PageSize * @PageIndex AND RowNumBer <= @PageSize * (@PageIndex + 1)
  ORDER BY RowNumBer
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Role_Search_Count]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Role_Search_Count]
(
	@RoleName nvarchar(100),
	@IsActive bit
)
AS
BEGIN
	SELECT COUNT(0) FROM PR_Role [Role]	WHERE [Role].RoleName LIKE '%'+@RoleName+'%' AND [Role].IsActive= @IsActive
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Role_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Role_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[PR_Role] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Role_SelectAll]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Role_SelectAll]

AS
BEGIN
	SELECT * FROM dbo.[PR_Role]
	ORDER BY SystemId, RoleName
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Role_SelectByName]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Role_SelectByName]
(
	@RoleName nvarchar(100)
)
AS
BEGIN
	SELECT * FROM dbo.[PR_Role] WHERE RoleName = @RoleName
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_Role_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_Role_Update]
(
	@Id uniqueidentifier,
	@SystemId uniqueidentifier,
	@RoleName nvarchar(100),
	@Description nvarchar(500),
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE PR_Role SET
		SystemId = @SystemId,
		RoleName = @RoleName,
		Description = @Description,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_SystemInfo_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_SystemInfo_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE PR_SystemInfo SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_SystemInfo_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_SystemInfo_Insert]
(
	@Id uniqueidentifier,
	@SystemName nvarchar(100),
	@Description nvarchar(500),
	@Url nvarchar(200),
	@AutoSignIn bit,
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[PR_SystemInfo]
	(
		Id,
		SystemName,
		Description,
		Url,
		AutoSignIn,
		IsActive
	)
	VALUES
	(
		@Id,
		@SystemName,
		@Description,
		@Url,
		@AutoSignIn,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_SystemInfo_Search]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_SystemInfo_Search]
(
	@SystemName nvarchar(100),
	@IsActive bit,
	@PageIndex int,
	@PageSize int
)AS
BEGIN

  SELECT * FROM
  (
	SELECT PR_SystemInfo.*, ROW_NUMBER() OVER(ORDER BY PR_SystemInfo.UpdateTimestamp DESC) AS RowNumBer FROM PR_SystemInfo
	WHERE PR_SystemInfo.SystemName LIKE '%'+@SystemName+'%' AND PR_SystemInfo.IsActive= @IsActive

   ) AS DataSet
  WHERE RowNumBer > @PageSize * @PageIndex AND RowNumBer <= @PageSize * (@PageIndex + 1)
  ORDER BY RowNumBer
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_SystemInfo_Search_Count]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_SystemInfo_Search_Count]
(
	@SystemName nvarchar(100),
	@IsActive bit
)
AS
BEGIN
	SELECT COUNT(0) FROM PR_SystemInfo [SystemInfo]	WHERE [SystemInfo].SystemName LIKE '%'+@SystemName+'%' AND [SystemInfo].IsActive= @IsActive
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_SystemInfo_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_SystemInfo_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[PR_SystemInfo] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_SystemInfo_SelectByName]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_SystemInfo_SelectByName]
(
	@SystemName nvarchar(100)
)
AS
BEGIN
	SELECT * FROM dbo.[PR_SystemInfo] WHERE SystemName = @SystemName
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_SystemInfo_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_SystemInfo_Update]
(
	@Id uniqueidentifier,
	@SystemName nvarchar(100),
	@Description nvarchar(500),
	@Url nvarchar(200),
	@AutoSignIn bit,
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE PR_SystemInfo SET
		SystemName = @SystemName,
		Description = @Description,
		Url = @Url,
		AutoSignIn = @AutoSignIn,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_User_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_User_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE PR_User SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_User_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_User_Insert]
(
	@Id uniqueidentifier,
	@UserId nvarchar(50),
	@UserName nvarchar(100),
	@Password nvarchar(500),
	@Mail nvarchar(200),
	@Department nvarchar(100),
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[PR_User]
	(
		Id,
		UserId,
		UserName,
		Password,
		Mail,
		Department,
		IsActive
	)
	VALUES
	(
		@Id,
		@UserId,
		@UserName,
		@Password,
		@Mail,
		@Department,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_User_Search]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_User_Search]
(
	@UserName nvarchar(100),
	@RoleName nvarchar(100),
	@IsActive bit,
	@PageIndex int,
	@PageSize int
)
AS
BEGIN
	IF(@RoleName IS NOT NULL AND LEN(@RoleName) >0)
		SELECT * FROM
		(
			SELECT DISTINCT PR_User.*, ROW_NUMBER() OVER(ORDER BY PR_User.UpdateTimestamp DESC) AS RowNumBer FROM PR_User
			WHERE EXISTS
			(
				SELECT [User].Id FROM PR_User [User]
				JOIN PR_User_Role [UserRole] ON [User].Id = [UserRole].UserId
				JOIN PR_Role [Role] ON [Role].Id = [UserRole].RoleId
				WHERE PR_User.Id = [User].Id AND [User].UserName LIKE '%'+@UserName+'%' AND [User].IsActive= @IsActive AND [Role].RoleName LIKE '%'+@RoleName+'%'
			)
		) AS DataSet
		WHERE RowNumBer > @PageSize * @PageIndex AND RowNumBer <= @PageSize * (@PageIndex + 1)
		ORDER BY RowNumBer
	ELSE
		SELECT * FROM
		(
			SELECT DISTINCT PR_User.*, ROW_NUMBER() OVER(ORDER BY PR_User.UpdateTimestamp DESC) AS RowNumBer FROM PR_User
			WHERE EXISTS
			(
				SELECT [User].Id FROM PR_User [User]
				WHERE PR_User.Id = [User].Id AND [User].UserName LIKE '%'+@UserName+'%' AND [User].IsActive= @IsActive
			)
		) AS DataSet
		WHERE RowNumBer > @PageSize * @PageIndex AND RowNumBer <= @PageSize * (@PageIndex + 1)
		ORDER BY RowNumBer
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_User_Search_Count]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_User_Search_Count]
(
	@UserName nvarchar(100),
	@RoleName nvarchar(100),
	@IsActive bit
)
AS
BEGIN
 IF(@RoleName IS NOT NULL AND LEN(@RoleName) >0)
	SELECT COUNT(0) FROM PR_User 
	WHERE EXISTS
	(
		SELECT DISTINCT [User].Id FROM PR_User [User]
		JOIN PR_User_Role [UserRole] ON [User].Id = [UserRole].UserId
		JOIN PR_Role [Role] ON [Role].Id = [UserRole].RoleId
		WHERE PR_User.Id = [User].Id AND [User].UserName LIKE '%'+@UserName+'%' AND [User].IsActive= @IsActive AND [Role].RoleName LIKE '%'+@RoleName+'%'
	)
 ELSE
	SELECT COUNT(0) FROM PR_User 
	WHERE EXISTS
	(
		SELECT [User].Id FROM PR_User [User]
		WHERE PR_User.Id = [User].Id AND [User].UserName LIKE '%'+@UserName+'%' AND [User].IsActive= @IsActive
	)
END

/****** Object:  StoredProcedure [dbo].[procPR_User_Search]    Script Date: 08/02/2012 10:20:58 ******/
SET ANSI_NULLS ON


GO
/****** Object:  StoredProcedure [dbo].[procPR_User_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_User_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[PR_User] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_User_SelectByName]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_User_SelectByName]
(
	@UserName nvarchar(100)
)
AS
BEGIN
	SELECT * FROM dbo.[PR_User] WHERE UserName = @UserName
END


GO
/****** Object:  StoredProcedure [dbo].[procPR_User_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procPR_User_Update]
(
	@Id uniqueidentifier,
	@UserId nvarchar(50),
	@UserName nvarchar(100),
	@Password nvarchar(500),
	@Mail nvarchar(200),
	@Department nvarchar(100),
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE PR_User SET
		UserId = @UserId,
		UserName = @UserName,
		Password = @Password,
		Mail = @Mail,
		Department = @Department,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Activity_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Activity_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE TR_Activity SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Activity_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Activity_Insert]
(
	@Id uniqueidentifier,
	@Title nvarchar(255),
	@LauncherId uniqueidentifier,
	@IsPublic bit,
	@IsApproved bit,
	@StartTime datetime,
	@EndTime datetime,
	@Description ntext,
	@IsActive bit,
	@InsertTimeStamp datetime,
	@UpdateTimeStamp datetime
)
AS
BEGIN
	INSERT INTO dbo.[TR_Activity]
	(
		Id,
		Title,
		LauncherId,
		IsPublic,
		IsApproved,
		StartTime,
		EndTime,
		Description,
		IsActive,
		InsertTimeStamp,
		UpdateTimeStamp
	)
	VALUES
	(
		@Id,
		@Title,
		@LauncherId,
		@IsPublic,
		@IsApproved,
		@StartTime,
		@EndTime,
		@Description,
		@IsActive,
		@InsertTimeStamp,
		@UpdateTimeStamp
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Activity_Search]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Activity_Search]
(
	@Type nvarchar(255),
	@Title nvarchar(255),
	@Launcher nvarchar(255),
	@Date datetime,
	@PageIndex int,
	@PageSize int
)
AS
BEGIN
	SELECT *
	FROM
	(
		SELECT TR_Activity.Id, ROW_NUMBER() OVER(ORDER BY TR_Activity.InsertTimeStamp DESC) AS RowNumber
		FROM TR_Activity
		WHERE Id IN
		(
			SELECT A.Id
			FROM TR_Activity AS A
			LEFT JOIN TR_Activity_ActivityType AS A_AT ON A.Id = A_AT.ActivityId AND A_AT.IsActive = 1
			RIGHT JOIN PR_ActivityType AS AT ON A_AT.TypeId = AT.Id AND AT.IsActive = 1
			INNER JOIN PR_User AS U ON A.LauncherId = U.Id AND U.IsActive = 1
			WHERE A.IsActive = 1
			AND A.IsApproved = 1
			AND A.EndTime >= @Date
			AND AT.Name LIKE '%' + @Type + '%'
			AND (A.Title LIKE '%' + @Title + '%' OR A.Description LIKE '%' + @Title)
			AND (U.UserId LIKE '%' + @Launcher + '%' OR U.UserName LIKE '%' + @Launcher + '%')
		)
	) AS AA
	WHERE RowNumber > @PageSize * @PageIndex AND RowNumber <= @PageSize * (@PageIndex + 1)
	ORDER BY RowNumber
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Activity_Search_Count]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Activity_Search_Count]
(
	@Type nvarchar(255),
	@Title nvarchar(255),
	@Launcher nvarchar(255),
	@Date datetime
)
AS
BEGIN
	SELECT COUNT(DISTINCT(A.Id))
	FROM TR_Activity AS A
	LEFT JOIN TR_Activity_ActivityType AS A_AT ON A.Id = A_AT.ActivityId AND A_AT.IsActive = 1
	RIGHT JOIN PR_ActivityType AS AT ON A_AT.TypeId = AT.Id AND AT.IsActive = 1
	INNER JOIN PR_User AS U ON A.LauncherId = U.Id AND U.IsActive = 1
	WHERE A.IsActive = 1
	AND A.IsApproved = 1
	AND A.EndTime >= @Date
	AND AT.Name LIKE '%' + @Type + '%'
	AND (A.Title LIKE '%' + @Title + '%' OR A.Description LIKE '%' + @Title)
	AND (U.UserId LIKE '%' + @Launcher + '%' OR U.UserName LIKE '%' + @Launcher + '%')
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Activity_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Activity_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[TR_Activity] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Activity_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Activity_Update]
(
	@Id uniqueidentifier,
	@Title nvarchar(255),
	@LauncherId uniqueidentifier,
	@IsPublic bit,
	@IsApproved bit,
	@StartTime datetime,
	@EndTime datetime,
	@Description ntext,
	@IsActive bit,
	@InsertTimeStamp datetime,
	@UpdateTimeStamp datetime
)
AS
BEGIN
	UPDATE TR_Activity SET
		Title = @Title,
		LauncherId = @LauncherId,
		IsPublic = @IsPublic,
		IsApproved = @IsApproved,
		StartTime = @StartTime,
		EndTime = @EndTime,
		Description = @Description,
		IsActive = @IsActive,
		InsertTimeStamp = @InsertTimeStamp,
		UpdateTimeStamp = @UpdateTimeStamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Attachment_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Attachment_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE TR_Attachment SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Attachment_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Attachment_Insert]
(
	@Id uniqueidentifier,
	@AttachmentName nvarchar(50),
	@DisplayName nvarchar(100),
	@AttachmentSize int,
	@CreatorId uniqueidentifier,
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[TR_Attachment]
	(
		Id,
		AttachmentName,
		DisplayName,
		AttachmentSize,
		CreatorId,
		IsActive
	)
	VALUES
	(
		@Id,
		@AttachmentName,
		@DisplayName,
		@AttachmentSize,
		@CreatorId,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Attachment_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Attachment_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[TR_Attachment] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Attachment_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Attachment_Update]
(
	@Id uniqueidentifier,
	@AttachmentName nvarchar(50),
	@DisplayName nvarchar(100),
	@AttachmentSize int,
	@CreatorId uniqueidentifier,
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE TR_Attachment SET
		AttachmentName = @AttachmentName,
		DisplayName = @DisplayName,
		AttachmentSize = @AttachmentSize,
		CreatorId = @CreatorId,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_AuditLog_DeleteAll]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_AuditLog_DeleteAll]
AS
BEGIN
	TRUNCATE TABLE TR_AuditLog
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_AuditLog_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_AuditLog_Insert]
(
	@Id uniqueidentifier,
	@OperationCode nvarchar(50),
	@Source nvarchar(50),
	@Category nvarchar(50),
	@UserName nvarchar(100),
	@Data nvarchar(max)
)
AS
BEGIN
	INSERT INTO dbo.[TR_AuditLog]
	(
		Id,
		OperationCode,
		Source,
		Category,
		UserName,
		Data
	)
	VALUES
	(
		@Id,
		@OperationCode,
		@Source,
		@Category,
		@UserName,
		@Data
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_AuditLog_Search]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_AuditLog_Search]
(
	@OperationCode nvarchar(50),
	@Source nvarchar(50),
	@Category nvarchar(50),
	@UserName nvarchar(100),
	@InsertTimestamp datetime,
	@PageIndex int,
	@PageSize int
)
AS
BEGIN
  SELECT * FROM
  (
	SELECT TR_AuditLog.*,ROW_NUMBER() OVER(ORDER BY TR_AuditLog.InsertTimestamp DESC) AS RowNumBer FROM TR_AuditLog
	WHERE OperationCode LIKE '%' + @OperationCode + '%' AND Source LIKE '%' + @Source + '%' AND TR_AuditLog.InsertTimestamp > @InsertTimestamp
	AND (Category IS NULL OR Category LIKE '%' + @Category + '%')
	AND UserName LIKE '%' + @UserName + '%'
  ) AS DataSet
  WHERE RowNumBer > @PageSize * @PageIndex AND RowNumBer <= @PageSize * (@PageIndex + 1)
  ORDER BY RowNumBer
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_AuditLog_Search_Count]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_AuditLog_Search_Count]
(
	@OperationCode nvarchar(50),
	@Source nvarchar(50),
	@Category nvarchar(50),
	@UserName nvarchar(100),
	@InsertTimestamp datetime
)
AS
BEGIN
	SELECT COUNT(0) FROM TR_AuditLog
	WHERE OperationCode LIKE '%' + @OperationCode + '%' AND Source LIKE '%' + @Source + '%' AND TR_AuditLog.InsertTimestamp > @InsertTimestamp
	AND (Category IS NULL OR Category LIKE '%' + @Category + '%')
	AND UserName LIKE '%' + @UserName + '%'
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_AuditLog_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_AuditLog_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[TR_AuditLog] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Attachment_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Attachment_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE TR_Issue_Attachment SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Attachment_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Attachment_Insert]
(
	@Id uniqueidentifier,
	@IssueId uniqueidentifier,
	@AttachmentId uniqueidentifier,
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[TR_Issue_Attachment]
	(
		Id,
		IssueId,
		AttachmentId,
		IsActive
	)
	VALUES
	(
		@Id,
		@IssueId,
		@AttachmentId,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Attachment_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Attachment_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[TR_Issue_Attachment] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Attachment_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Attachment_Update]
(
	@Id uniqueidentifier,
	@IssueId uniqueidentifier,
	@AttachmentId uniqueidentifier,
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE TR_Issue_Attachment SET
		IssueId = @IssueId,
		AttachmentId = @AttachmentId,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE TR_Issue SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Insert]
(
	@Id uniqueidentifier,
	@IssueTitle nvarchar(200),
	@Description nvarchar(max),
	@OwnerId uniqueidentifier,
	@Comments nvarchar(max),
	@Status nvarchar(50),
	@CreatorId uniqueidentifier,
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[TR_Issue]
	(
		Id,
		IssueTitle,
		Description,
		OwnerId,
		Comments,
		Status,
		CreatorId,
		IsActive
	)
	VALUES
	(
		@Id,
		@IssueTitle,
		@Description,
		@OwnerId,
		@Comments,
		@Status,
		@CreatorId,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Search]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Search]
(
	@IssueTitle nvarchar(200),
	@Status nvarchar(50),
	@OwnerName nvarchar(100),
	@CreatorName nvarchar(100),
	@IsActive bit,
	@PageIndex int,
	@PageSize int
)
AS
BEGIN
    SELECT * FROM
    (
		SELECT [TR_Issue].*, ROW_NUMBER() OVER(ORDER BY dbo.[TR_Issue].UpdateTimestamp DESC) AS RowNumBer FROM dbo.[TR_Issue]
		JOIN PR_User AS [Owner] ON TR_Issue.OwnerId = [Owner].Id
		JOIN PR_User AS Creator ON TR_Issue.CreatorId = Creator.Id
		WHERE IssueTitle LIKE '%'+ @IssueTitle +'%' AND [Status] LIKE '%' + @Status + '%' AND TR_Issue.IsActive = @IsActive
		AND [Owner].UserName LIKE '%' + @OwnerName + '%'
		AND Creator.UserName LIKE '%' + @CreatorName + '%'
    ) AS DataSet
    WHERE RowNumBer > @PageSize * @PageIndex AND RowNumBer <= @PageSize * (@PageIndex + 1)
    ORDER BY RowNumBer 
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Search_Count]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Search_Count]
(
	@IssueTitle nvarchar(200),
	@Status nvarchar(50),
	@OwnerName nvarchar(100),
	@CreatorName nvarchar(100),
	@IsActive bit
)
AS
BEGIN
	SELECT COUNT(0) FROM dbo.[TR_Issue]
	JOIN PR_User AS [Owner] ON TR_Issue.OwnerId = [Owner].Id
	JOIN PR_User AS Creator ON TR_Issue.CreatorId = Creator.Id
	WHERE IssueTitle LIKE '%'+ @IssueTitle +'%' AND [Status] LIKE '%' + @Status + '%' AND TR_Issue.IsActive = @IsActive
	AND [Owner].UserName LIKE '%' + @OwnerName + '%'
	AND Creator.UserName LIKE '%' + @CreatorName + '%'
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[TR_Issue] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Issue_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Issue_Update]
(
	@Id uniqueidentifier,
	@IssueTitle nvarchar(200),
	@Description nvarchar(max),
	@OwnerId uniqueidentifier,
	@Comments nvarchar(max),
	@Status nvarchar(50),
	@CreatorId uniqueidentifier,
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE TR_Issue SET
		IssueTitle = @IssueTitle,
		Description = @Description,
		OwnerId = @OwnerId,
		Comments = @Comments,
		Status = @Status,
		CreatorId = @CreatorId,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Log_DeleteAll]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Log_DeleteAll]
AS
BEGIN
	TRUNCATE TABLE TR_Log
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Log_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Log_Insert]
(
	@Id uniqueidentifier,
	@Level nvarchar(50),
	@Source nvarchar(50),
	@Category nvarchar(50),
	@EventId nvarchar(50),
	@UserName nvarchar(100),
	@Data nvarchar(max)
)
AS
BEGIN
	INSERT INTO dbo.[TR_Log]
	(
		Id,
		Level,
		Source,
		Category,
		EventId,
		UserName,
		Data
	)
	VALUES
	(
		@Id,
		@Level,
		@Source,
		@Category,
		@EventId,
		@UserName,
		@Data
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Log_Search]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Log_Search]
(
	@Level nvarchar(50),
	@Source nvarchar(50),
	@Category nvarchar(50),
	@EventId nvarchar(50),
	@InsertTimestamp datetime,
	@PageIndex int,
	@PageSize int
)
AS
BEGIN
  SELECT * FROM
  (
	SELECT TR_Log.*, ROW_NUMBER() OVER(ORDER BY dbo.TR_Log.InsertTimestamp DESC) AS RowNumBer FROM TR_Log WHERE
		[Level] LIKE '%' + @Level + '%' AND
		Source LIKE '%' + @Source + '%' AND
		(Category IS NULL OR Category LIKE '%' + @Category + '%') AND
		(EventId IS NULL OR EventId LIKE '%' + @EventId + '%') AND
		InsertTimestamp > @InsertTimestamp
  ) AS DataSet
  WHERE RowNumBer > @PageSize * @PageIndex AND RowNumBer <= @PageSize * (@PageIndex + 1)
  ORDER BY RowNumBer
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Log_Search_Count]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Log_Search_Count]
(
	@Level nvarchar(50),
	@Source nvarchar(50),
	@Category nvarchar(50),
	@EventId nvarchar(50),
	@InsertTimestamp datetime
)
AS
BEGIN
	SELECT COUNT(0) FROM TR_Log WHERE
		[Level] LIKE '%' + @Level + '%' AND
		Source LIKE '%' + @Source + '%' AND
		(Category IS NULL OR Category LIKE '%' + @Category + '%') AND
		(EventId IS NULL OR EventId LIKE '%' + @EventId + '%') AND
		InsertTimestamp > @InsertTimestamp
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Log_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Log_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[TR_Log] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Participation_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Participation_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE TR_Participation SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Participation_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Participation_Insert]
(
	@Id uniqueidentifier,
	@UserId uniqueidentifier,
	@ActivityId uniqueidentifier,
	@Fellow int,
	@Comments nvarchar(255),
	@IsApproved bit,
	@IsActive bit,
	@InsertTimeStamp datetime,
	@UpdateTimeStamp datetime
)
AS
BEGIN
	INSERT INTO dbo.[TR_Participation]
	(
		Id,
		UserId,
		ActivityId,
		Fellow,
		Comments,
		IsApproved,
		IsActive,
		InsertTimeStamp,
		UpdateTimeStamp
	)
	VALUES
	(
		@Id,
		@UserId,
		@ActivityId,
		@Fellow,
		@Comments,
		@IsApproved,
		@IsActive,
		@InsertTimeStamp,
		@UpdateTimeStamp
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Participation_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Participation_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[TR_Participation] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Participation_SelectByUserIdAndActivityId]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[procTR_Participation_SelectByUserIdAndActivityId]
	@UserId uniqueIDENTIFIER, 
	@ActivityId uniqueIDENTIFIER
AS
BEGIN
	SET NOCOUNT ON;
	SELECT *
	FROM TR_Participation
	WHERE IsActive = 1
	AND UserId = @UserId
	AND ActivityId = @ActivityId
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Participation_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Participation_Update]
(
	@Id uniqueidentifier,
	@UserId uniqueidentifier,
	@ActivityId uniqueidentifier,
	@Fellow int,
	@Comments nvarchar(255),
	@IsApproved bit,
	@IsActive bit,
	@InsertTimeStamp datetime,
	@UpdateTimeStamp datetime
)
AS
BEGIN
	UPDATE TR_Participation SET
		UserId = @UserId,
		ActivityId = @ActivityId,
		Fellow = @Fellow,
		Comments = @Comments,
		IsApproved = @IsApproved,
		IsActive = @IsActive,
		InsertTimeStamp = @InsertTimeStamp,
		UpdateTimeStamp = @UpdateTimeStamp
	WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Token_Delete]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Token_Delete]
(
	@Id uniqueidentifier
)
AS
BEGIN
	UPDATE TR_Token SET IsActive = 0 WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Token_Erasure]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Token_Erasure]
(
	@Id uniqueidentifier
)
AS
BEGIN
	DELETE FROM TR_Token WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Token_Insert]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Token_Insert]
(
	@Id uniqueidentifier,
	@UserId uniqueidentifier,
	@UserName nvarchar(100),
	@SecurityKey nvarchar(100),
	@ExpirationDate datetime,
	@IssuedBy nvarchar(50),
	@IsActive bit
)
AS
BEGIN
	INSERT INTO dbo.[TR_Token]
	(
		Id,
		UserId,
		UserName,
		SecurityKey,
		ExpirationDate,
		IssuedBy,
		IsActive
	)
	VALUES
	(
		@Id,
		@UserId,
		@UserName,
		@SecurityKey,
		@ExpirationDate,
		@IssuedBy,
		@IsActive
	)
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Token_Select]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Token_Select]
(
	@Id uniqueidentifier
)
AS
BEGIN
	SELECT * FROM dbo.[TR_Token] WHERE Id = @Id
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Token_SelectByUserName]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Token_SelectByUserName]
(
	@UserName nvarchar(100)
)
AS
BEGIN
	SELECT * FROM dbo.[TR_Token] WHERE UserName = @UserName
END


GO
/****** Object:  StoredProcedure [dbo].[procTR_Token_Update]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[procTR_Token_Update]
(
	@Id uniqueidentifier,
	@UserId uniqueidentifier,
	@UserName nvarchar(100),
	@SecurityKey nvarchar(100),
	@ExpirationDate datetime,
	@IssuedBy nvarchar(50),
	@IsActive bit,
	@UpdateTimestamp datetime
)
AS
BEGIN
	UPDATE TR_Token SET
		UserId = @UserId,
		UserName = @UserName,
		SecurityKey = @SecurityKey,
		ExpirationDate = @ExpirationDate,
		IssuedBy = @IssuedBy,
		IsActive = @IsActive,
		UpdateTimestamp = @UpdateTimestamp
	WHERE Id = @Id
END


GO
/****** Object:  Table [dbo].[PR_ActivityType]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PR_ActivityType](
	[Id] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](255) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[IsActive] [bit] NULL,
	[InsertTimeStamp] [datetime] NOT NULL,
	[UpdateTimeStamp] [datetime] NOT NULL,
 CONSTRAINT [PK_PR_ActivityType] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PR_Page]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PR_Page](
	[Id] [uniqueidentifier] NOT NULL,
	[PageName] [nvarchar](100) NOT NULL,
	[Url] [nvarchar](500) NULL,
	[Category] [nvarchar](100) NULL,
	[NavigationOrder] [int] NULL,
	[NavigationType] [nvarchar](50) NOT NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_PR_Page] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PR_Permission]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PR_Permission](
	[Id] [uniqueidentifier] NOT NULL,
	[PermissionName] [nvarchar](100) NOT NULL,
	[IsSystemData] [bit] NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_PR_Permission] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PR_Role]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PR_Role](
	[Id] [uniqueidentifier] NOT NULL,
	[RoleName] [nvarchar](100) NOT NULL,
	[Description] [nvarchar](500) NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
	[SystemId] [uniqueidentifier] NULL,
 CONSTRAINT [PK_PR_Role] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PR_Role_Permission]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PR_Role_Permission](
	[Id] [uniqueidentifier] NOT NULL,
	[PageId] [uniqueidentifier] NOT NULL,
	[RoleId] [uniqueidentifier] NOT NULL,
	[PermissionId] [uniqueidentifier] NOT NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_PR_RolePermission] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PR_SystemInfo]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PR_SystemInfo](
	[Id] [uniqueidentifier] NOT NULL,
	[SystemName] [nvarchar](100) NOT NULL,
	[Description] [nvarchar](500) NULL,
	[Url] [nvarchar](200) NULL,
	[AutoSignIn] [bit] NOT NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_PR_SystemInfo] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PR_User]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PR_User](
	[Id] [uniqueidentifier] NOT NULL,
	[UserId] [nvarchar](50) NOT NULL,
	[UserName] [nvarchar](100) NOT NULL,
	[Password] [nvarchar](500) NULL,
	[Mail] [nvarchar](200) NOT NULL,
	[Department] [nvarchar](100) NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_PR_User] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[PR_User_Role]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PR_User_Role](
	[Id] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[RoleId] [uniqueidentifier] NOT NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_PR_UserRole] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_Activity]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_Activity](
	[Id] [uniqueidentifier] NOT NULL,
	[Title] [nvarchar](255) NOT NULL,
	[LauncherId] [uniqueidentifier] NOT NULL,
	[IsPublic] [bit] NOT NULL,
	[IsApproved] [bit] NOT NULL,
	[StartTime] [datetime] NOT NULL,
	[EndTime] [datetime] NOT NULL,
	[Description] [nvarchar](max) NULL,
	[IsActive] [bit] NULL,
	[InsertTimeStamp] [datetime] NOT NULL,
	[UpdateTimeStamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TR_Activity] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_Activity_ActivityType]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_Activity_ActivityType](
	[Id] [uniqueidentifier] NOT NULL,
	[TypeId] [uniqueidentifier] NOT NULL,
	[ActivityId] [uniqueidentifier] NOT NULL,
	[IsActive] [bit] NULL,
 CONSTRAINT [PK_TR_Activity_ActivityType] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_Attachment]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_Attachment](
	[Id] [uniqueidentifier] NOT NULL,
	[AttachmentName] [nvarchar](50) NOT NULL,
	[DisplayName] [nvarchar](100) NOT NULL,
	[AttachmentSize] [int] NOT NULL,
	[CreatorId] [uniqueidentifier] NOT NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TR_Attachment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_AuditLog]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_AuditLog](
	[Id] [uniqueidentifier] NOT NULL,
	[OperationCode] [nvarchar](50) NOT NULL,
	[Source] [nvarchar](50) NOT NULL,
	[Category] [nvarchar](50) NULL,
	[UserName] [nvarchar](100) NULL,
	[Data] [nvarchar](max) NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TS_AuditLog] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_Issue]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_Issue](
	[Id] [uniqueidentifier] NOT NULL,
	[IssueTitle] [nvarchar](200) NOT NULL,
	[Description] [nvarchar](max) NULL,
	[OwnerId] [uniqueidentifier] NULL,
	[Comments] [nvarchar](max) NULL,
	[Status] [nvarchar](50) NOT NULL,
	[CreatorId] [uniqueidentifier] NOT NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TR_Issue] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_Issue_Attachment]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_Issue_Attachment](
	[Id] [uniqueidentifier] NOT NULL,
	[IssueId] [uniqueidentifier] NOT NULL,
	[AttachmentId] [uniqueidentifier] NOT NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TR_Issue_Attachment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_Log]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_Log](
	[Id] [uniqueidentifier] NOT NULL,
	[Level] [nvarchar](50) NOT NULL,
	[Source] [nvarchar](50) NOT NULL,
	[Category] [nvarchar](50) NULL,
	[EventId] [nvarchar](50) NULL,
	[UserName] [nvarchar](100) NULL,
	[Data] [nvarchar](max) NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TR_Log] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_Participation]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_Participation](
	[Id] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[ActivityId] [uniqueidentifier] NOT NULL,
	[Fellow] [int] NULL,
	[Comments] [nvarchar](255) NULL,
	[IsApproved] [bit] NULL,
	[IsActive] [bit] NULL,
	[InsertTimeStamp] [datetime] NOT NULL,
	[UpdateTimeStamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TR_User_Activity] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
/****** Object:  Table [dbo].[TR_Token]    Script Date: 2012/10/22 22:40:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TR_Token](
	[Id] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[UserName] [nvarchar](100) NOT NULL,
	[SecurityKey] [nvarchar](100) NOT NULL,
	[ExpirationDate] [datetime] NOT NULL,
	[IssuedBy] [nvarchar](50) NOT NULL,
	[IsActive] [bit] NULL,
	[InsertTimestamp] [datetime] NOT NULL,
	[UpdateTimestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_TR_Token] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
